/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module settlbat.h - Functions for the batch history fucntionality |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Include/settlbat.h $ 

**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#ifndef VSSTLBAT_H
#define VSSTLBAT_H

#include <batch.h>
#include <form.h>

#define KEY_BATCH_NUM   201        /* Invoice number is the key  */
#define KEY_SETT_DATE   202        /* Offline Flag is the key */

/* Batch record update actions based on an index */

#define MAX_SETT_CNT    7          /* Maximum number of settrec/host */

/* Settlement Batch record and key data structure */

typedef struct TagSETT_REC
{
    TOTALS_FORM srTerminal;

    char szDate[DATE_SIZE + 1];
    char szTime[TIME_SIZE + 1];
    char szBatchNum[BATCH_NUM_SIZE + 1];
    char szHostName[HOST_NAME_SIZE + 1];
    char szSettleResp[SETTLE_RESP_SIZE];

} SETT_REC;

#define SIZE_SETT_REC         sizeof(SETT_REC)

typedef struct TagSETT_KEY
{
    long    lnRecNum;                          /* Compulsary for DBFM   */
    char    szDate[DATE_SIZE + 1];
    char    szBatchNum[BATCH_NUM_SIZE + 1];
} SETT_KEY;

#define SIZE_SETT_KEY         sizeof(SETT_KEY)

typedef struct TagSETT_SKEY {
    int         (*compare_func) ();
    int         inKeyIdx;
    SETT_KEY	srSettKey;
} SETT_SKEY;

static void vdGetSettFName (char *pchBFName);
static int inOpenSett (DB_FILE *psrDBFPtr, char *pchFName);
static int inCloseSett (DB_FILE *psrDBFPtr);
static int inClearSett (void);
static int inAddSettRec (TRANSACTION_OBJECT *pobTran, char *szFileName, DB_FILE *psrDBFPtr, long  lnRecNum, SETT_REC *psrSRec, SETT_KEY *psrSKey);
static void vdFormSettKey (TRANSACTION_OBJECT *pobTran, SETT_KEY *psrSKey);
int inPutSettRec (TRANSACTION_OBJECT *pobTran, SETT_REC *psrSRec, SETT_KEY *psrSKey);
static int inGetSettRec (TRANSACTION_OBJECT *pobTran, long lnRecNum, SETT_REC *psrSRec, SETT_KEY *psrSKey);
static int inSettCompFn (SETT_KEY *psrSKey, SETT_SKEY *MatchKey);
static int inKeySettFindRead (DB_FILE *psrDBFPtr, SETT_REC *psrSRec, SETT_KEY *psrSKey, int inKeyIdx, long *plnRecNum);
static int inGetKeySettRec (TRANSACTION_OBJECT *pobTran, SETT_REC *psrSRec, SETT_KEY *psrSKey, int inKeyIdx, long *plnRecNum);
long lnGetSettRecCnt (void);
int inLoadSettRec (TRANSACTION_OBJECT *pobTran, SETT_REC * psrLocSRec, SETT_KEY * psrLocSKey, long lnRecNum);
int inGetBatchNumSettRec (TRANSACTION_OBJECT *pobTran, SETT_REC * psrLocSRec, SETT_KEY * psrLocSKey);
int inGetDateSettRec (TRANSACTION_OBJECT *pobTran, SETT_REC * psrLocSRec, SETT_KEY * psrLocSKey, long *plnRecNum);
static int inDeleteEighthBatRec (void);
static VS_BOOL fSettEmpty (void);
int inSettleOperation (TRANSACTION_OBJECT *pobTran);
int SETTLBAT_CODE_CHECK(char * a,char *b,short *  c,char * d,unsigned char * e);

#endif  /* VSSTLBAT_H */
